<?php
declare(strict_types=1);
namespace Dao;
// hook dao_sys_album_use.php

use Model\WsModel;

class WsDao extends WsModel
{
	// hook dao_sys_album_public_start.php

	protected array $add_rule	=	[];
    protected array $edit_rule	=	[];

    protected array $rule	=	[
		/*
		"mobile"=>[
			"max"=>3
			"min"=>3
			"func"=>'isMobile'
			"error"=>false,
			'message'=>'格式有误'
		],
		"username"=>[
			"max"=>3
			"min"=>3
			"func"=>'checkS'
			"error"=>false,
			'message'=>'格式有误'
		],
		*/
	];
	//数据，字段，验证规则
	/*
	function isMobile($data,$field,$val){
	
		return true;
	}
	*/
	
	// hook dao_sys_album_public_end.php


    public function add_uid_fd($uid, $fd)
    {
        $this->delete(['fd' => $fd]);
        $this->insert(['uid' => $uid,'fd' => $fd]);
    }

    public function add_gid_uid($gid, $uid)
    {
        $this->update(['uid' => $uid], ['gid' => $gid]);
    }

    public function add_gid_fd($gid, $fd)
    {
        $this->update(['fd' => $fd], ['gid' => $gid]);
    }

    public function find_fd_by_uid($uid = 0)
    {
        $data = $this->select(['uid' => $uid]);
        return array_filter_empty_unique($data, 'fd');
    }

    public function all()
    {
        return  $this->select();
    }

    public function find_uid_by_fd($fd = 0)
    {
        $data = $this->select(['fd' => $fd]);
        return array_filter_empty_unique($data, 'fd');
    }

    public function find_fd_by_gid($gid)
    {
        $data = $this->select(['gid' => $gid]);
        return array_filter_empty_unique($data, 'fd');
    }

    public function find_uid_by_gid($gid)
    {
        $data = $this->select(['gid' => $gid]);
        return array_filter_empty_unique($data, 'uid');
    }

    public function unGroup($gid)
    {
        $this->update(['gid' => $gid], ['gid' => 0]);
    }

    // $fd = 0 -- 删除所有
    public function del_uid_fd($uid, $fd = 0)
    {

        $cond = ['uid' => $uid];
        if ($fd) {
            $cond['fd'] = $fd;
        }
        $this->delete($cond);
    }

    public function del_fd($fd)
    {
        $this->delete(['fd' => $fd]);
    }


    // hook dao_sys_album_end.php
}
?>